package com.mindskip.xzs.schedule;

import com.mindskip.xzs.service.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.SchedulingConfigurer;
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author artka
 * @description: 定时同步
 * @date 2022/9/13 9:15 PM
 */
@Slf4j
@Component
public class MySchedule implements SchedulingConfigurer {

    @Resource
    private Task task;

    @Value("${schedule.cron.updateDeptAndUser}")
    private String cron;

    /**
     * 定时任务
     */
    @Override
    @Async
    public void configureTasks(ScheduledTaskRegistrar scheduledTaskRegistrar) {
        // 定时同步企业微信组织架构
        scheduledTaskRegistrar.addCronTask(
                //1.添加任务内容
                task::task,
                //2.设置定时时间
                cron
        );
        // 定时更新分类数据
/*        scheduledTaskRegistrar.addFixedDelayTask(
                //1.添加任务内容
                () -> {
                    long startTime = System.currentTimeMillis();
                    newQuestionService.updateCategorysInCache();
                    examService.updateCategorysInCache();
                    examService.updateExamKVInCache();
                    examPaperService.updatePaperKVInCache();
                    qywxService.getDepartAndUserTree(false);
                    departmentService.updateDeptsKVInCache();
                    newUserService.updateUserKVInCache();
                    long endTime = System.currentTimeMillis();
                    log.info("定时同步缓存数据成功，耗时:{}秒", (endTime - startTime) / 1000);
                },
                //2.设置延迟时间 毫秒
                1000 * 60 * 60 * 12
        );*/
    }
}
